package com.likejian.rabbit.control;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.likejian.rabbit.fanout.FanoutSender;
import com.likejian.rabbit.simple.SimpleSender;
import com.likejian.rabbit.simple.UserSender;
import com.likejian.rabbit.topic.TopicSender;

@RestController
public class SendControl {

	@Autowired
	private SimpleSender simpleSender;
	@Autowired
	private UserSender userSender;
	@Autowired
	private TopicSender topicSender;
	@Autowired
	private FanoutSender fanoutSender;
	
	@GetMapping("/send/{message}")
	public String send(@PathVariable String message){
		for (int i = 0; i < 1000; i++) {
			simpleSender.send(message);
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return message;
	}
	
	@GetMapping("/senduser/{name}")
	public String senduser(@PathVariable String name){
		for (int i = 0; i < 1000; i++) {
			userSender.send(name);
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return name;
	}
	
	@GetMapping("/topic/send")
	public String topicSend(){
		for (int i = 0; i < 1000; i++) {
			topicSender.send();
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return "";
	}
	
	@GetMapping("/fanout/send")
	public String fanoutSend(){
		for (int i = 0; i < 1000; i++) {
			fanoutSender.send();
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return "";
	}
}
